// 
// Creative Software Group� - http://www.creativesoftwaregroup.com 
// Copyright (c) 2010-2013 
// by Creative Software Group Corporation 
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software. 
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE. 
// 

using System;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using System.Collections.Generic;

using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Search;
using DotNetNuke.Entities.Modules;

namespace CSG.Modules.aNvarCharTest
{

    /// ----------------------------------------------------------------------------- 
    /// <summary> 
    /// The Controller class for aNvarCharTest 
    /// </summary> 
    /// <remarks> 
    /// </remarks> 
    /// <history> 
    /// </history> 
    /// ----------------------------------------------------------------------------- 
    public class aNvarCharTestController : ISearchable, IPortable
    {

        #region "Public Methods"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// gets an object from the database 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModuleId">The Id of the module may or may not be needed depending how the generator was configured when generating this method.</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public List<aNvarCharTestInfo> GetaNvarCharTests()
        {

            return CBO.FillCollection<aNvarCharTestInfo>(DataProvider.Instance().GetaNvarCharTests());

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// gets an object from the database 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModuleId">The Id of the module</param> 
        /// <param name="ItemId">The Id of the item</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public aNvarCharTestInfo GetaNvarCharTest(int aNvarChar_PK)
        {

            return (aNvarCharTestInfo)CBO.FillObject(DataProvider.Instance().GetaNvarCharTest(aNvarChar_PK), typeof(aNvarCharTestInfo));

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// adds an object to the database 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="objaNvarCharTest">The aNvarCharTestInfo object</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public void AddaNvarCharTest(aNvarCharTestInfo objaNvarCharTest)
        {

            //if (objaNvarCharTest.Content.Trim() != "")
            //{
            DataProvider.Instance().AddaNvarCharTest(objaNvarCharTest.nvarchar10, objaNvarCharTest.nvarchar25, objaNvarCharTest.nvarchar50, objaNvarCharTest.nvarcharMax, objaNvarCharTest.VarcharMax);
            //}

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// saves an object to the database 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="objaNvarCharTest">The aNvarCharTestInfo object</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public void UpdateaNvarCharTest(aNvarCharTestInfo objaNvarCharTest)
        {

            //if (objaNvarCharTest.Content.Trim() != "")
            //{
            DataProvider.Instance().UpdateaNvarCharTest(objaNvarCharTest.aNvarChar_PK, objaNvarCharTest.nvarchar10, objaNvarCharTest.nvarchar25, objaNvarCharTest.nvarchar50, objaNvarCharTest.nvarcharMax, objaNvarCharTest.VarcharMax);
            //}

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// deletes an object from the database 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModuleId">The Id of the module</param> 
        /// <param name="ItemId">The Id of the item</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public void DeleteaNvarCharTest(int aNvarChar_PK)
        {

            DataProvider.Instance().DeleteaNvarCharTest(aNvarChar_PK);

        }

        #endregion

        #region "Optional Interfaces"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// GetSearchItems implements the ISearchable Interface 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public DotNetNuke.Services.Search.SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {

            SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();

            List<aNvarCharTestInfo> colaNvarCharTests = GetaNvarCharTests();
            foreach (aNvarCharTestInfo objaNvarCharTest in colaNvarCharTests)
            {

                // If you want to the DNN Search engine to find results from this module, you will need to hand code the the line below to indicate what field in the table is searchable
                //SearchItemInfo SearchItem = new SearchItemInfo(ModInfo.ModuleTitle, objaNvarCharTest.{searchable field here} objaNvarCharTest.CreatedByUser, objaNvarCharTest.CreatedDate, ModInfo.ModuleID, objaNvarCharTest.$tablePk$.ToString(), objaNvarCharTest.{searchable field here}, "$tablePk$=" + objaNvarCharTest.$tablePk$.ToString()); 
                //SearchItemCollection.Add(SearchItem); 

            }

            return SearchItemCollection;

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// ExportModule implements the IPortable ExportModule Interface 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModuleId">The Id of the module to be exported</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public string ExportModule(int ModuleId)
        {

            string strXML = "";

            List<aNvarCharTestInfo> colaNvarCharTests = GetaNvarCharTests();
            if (colaNvarCharTests.Count != 0)
            {
                strXML += "<aNvarCharTests>";
                foreach (aNvarCharTestInfo objaNvarCharTest in colaNvarCharTests)
                {
                    strXML += "<aNvarCharTest>";

                    // Finish UserInputForm.CreateControllerExportModuleScripter() Line 986

                    // strXML += "<content>" + XmlUtils.XMLEncode(objaNvarCharTest.Content) + "</content>"; 
                    strXML += "</aNvarCharTest>";
                }
                strXML += "</aNvarCharTests>";
            }

            return strXML;

        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// ImportModule implements the IPortable ImportModule Interface 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <param name="ModuleID">The Id of the module to be imported</param> 
        /// <param name="Content">The content to be imported</param> 
        /// <param name="Version">The version of the module to be imported</param> 
        /// <param name="UserId">The Id of the user performing the import</param> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {

            XmlNode xmlaNvarCharTests = Globals.GetContent(Content, "aNvarCharTests");
            foreach (XmlNode xmlaNvarCharTest in xmlaNvarCharTests.SelectNodes("aNvarCharTest"))
            {
                aNvarCharTestInfo objaNvarCharTest = new aNvarCharTestInfo();
                //objaNvarCharTest.ModuleId = ModuleID; 

                // Finish UserInputForm.CreateControllerImportModuleScripter() Line 979

                // objaNvarCharTest.Content = xmlaNvarCharTest.SelectSingleNode("content").InnerText; 
                // objaNvarCharTest.CreatedByUser = UserId; 
                AddaNvarCharTest(objaNvarCharTest);
            }

        }

        #endregion

    }
}